/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"5738E2B2-C9DE-48DE-871F-F7F0020631E3",variableType:8}
 */
var t_ib = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"E5745E00-2E3E-42F7-8D14-E8292DE2C7CF",variableType:8}
 */
var t_iva_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"7A70D246-807E-4F7D-9AE9-507FE3D6200F",variableType:8}
 */
var t_iva_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"16377A83-AF89-49A5-86AE-E6948A0982AB",variableType:8}
 */
var t_iva_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"CB92449A-1BD6-4529-BD4E-B78FFDCD73D0",variableType:8}
 */
var t_iva_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"FF7DA1F0-62E8-4343-8EED-FFF2C8A5B1D0",variableType:8}
 */
var t_neto_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C96E2045-CC6C-4C37-90CC-B07893DE9F10",variableType:8}
 */
var t_neto_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"5A6FF8A7-59EE-4EEB-91B5-F452B3A74DCF",variableType:8}
 */
var t_neto_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"E4E5ED7D-5BB9-4A24-B5F2-BEB18DAB1CA8",variableType:8}
 */
var t_neto_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"EB6F2275-40AC-4415-9997-C4831AEB5A8E",variableType:8}
 */
var porc_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"581260BA-32D0-499D-913E-B18AAA49D07E",variableType:8}
 */
var porc_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"5EB70C92-7552-4817-8ED8-B33C86DAFE0C",variableType:8}
 */
var porc_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"EEA35660-0BB9-46AF-A0B2-0BFB54451E94",variableType:8}
 */
var porc_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"FF7586CD-4739-4855-BAAC-27D092A6DDD4",variableType:8}
 */
var t_importe = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"60E5B137-972C-48E2-A7F1-8DC104BF6B7D",variableType:8}
 */
var t_iva = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"FFFBA70E-65DF-4989-B85E-0B97367DD85F",variableType:8}
 */
var t_neto = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"0DCB0037-DDD5-461A-BEBF-3D57077D3C33",variableType:8}
 */
var t_neto_no_gravado = null;

/**
 * @properties={typeid:24,uuid:"165E7E33-A219-458E-AA7B-D132FD7886B0"}
 */
function queryTotales() {
	
	// TENGO Q AGREGAR ALGO POR LETRA == 'E' ????
	
	var $fechaDesde = globals.gFechaDesde
	$fechaDesde.setHours(00)
	$fechaDesde.setMinutes(00)
	$fechaDesde.setSeconds(00)
	$fechaDesde.setMilliseconds(000)
	var $fDesde = utils.dateFormat($fechaDesde,'yyyy-MM-dd HH:mm:ss')
	var $fechaHasta = globals.gFechaHasta
	$fechaHasta.setHours(23)
	$fechaHasta.setMinutes(59)
	$fechaHasta.setSeconds(59)
	$fechaHasta.setMilliseconds(996)
	var $fHasta = utils.dateFormat($fechaHasta,'yyyy-MM-dd HH:mm:ss')

	var $queryTotales = 'SELECT SUM(neto_no_gravado_signo) as "t_neto_no_gravado", SUM(neto_signo) as "t_neto", '+ 
				'SUM(iva_signo) as "t_iva", SUM(ib_percep_signo) as "t_ib", SUM(importe_signo) as "t_importe" '+ 
				' FROM ctacte_cl as "cc" '+
				'INNER JOIN tab_mov_cl as "tb" ON cc.cod_mov = tb.ctacte_mov_cl_id '+ 
				'WHERE cc.userv_id = ? and cc.fecha_mov BETWEEN ? and ? and tb.diario_ventas = 1 group by cc.userv_id'
	var argsTotales = [globals.gUservID,$fechaDesde,$fechaHasta]
	var $totales 	= databaseManager.getDataSetByQuery('infocom',$queryTotales,argsTotales,-1)
	
	
	var queryTasaIva = 'SELECT ti.tasa_iva_id, ti.tasa_iva_porc, ' + globals.gCharNull + '((select SUM(neto_signo) from ctacte_cl as "sc" INNER JOIN tab_mov_cl tb ON sc.cod_mov = ctacte_mov_cl_id where ti.tasa_iva_porc = sc.iva_porc and sc.fecha_mov BETWEEN \'' + $fDesde + '\' and \'' + $fHasta +'\' and  tb.diario_ventas = 1),0) as "t_neto", '+ 
						globals.gCharNull + '((select SUM(iva_signo) from ctacte_cl as "sc" INNER JOIN tab_mov_cl tb ON sc.cod_mov = ctacte_mov_cl_id where ti.tasa_iva_id = sc.tasa_iva_id and sc.fecha_mov BETWEEN \'' + $fDesde + '\' and \'' + $fHasta +'\' and  tb.diario_ventas = 1),0) as "t_iva" '+  
						'FROM tasa_iva as "ti" ' +
						'GROUP BY ti.tasa_iva_porc, ti.tasa_iva_id ORDER BY ti.tasa_iva_porc'					
						
	var argsTasas	= []
	var $tasasIva 	= databaseManager.getDataSetByQuery('infocom',queryTasaIva,argsTasas,-1)
	
	//Indices de Totales
	var iNetoNoG	= $totales.getColumnNames().indexOf("t_neto_no_gravado",0) + 1 
	var iNeto		= $totales.getColumnNames().indexOf("t_neto",0) + 1
	var iIva		= $totales.getColumnNames().indexOf("t_iva",0) + 1
	var iIB			= $totales.getColumnNames().indexOf("t_ib",0) + 1
	var iImporte	= $totales.getColumnNames().indexOf("t_importe",0) + 1 
	
	
	//Indices de las tasas
	var iIvaPorc	= $tasasIva.getColumnNames().indexOf("tasa_iva_porc",0) + 1
	var iTNeto		= $tasasIva.getColumnNames().indexOf("t_neto",0) + 1
	var iTIva		= $tasasIva.getColumnNames().indexOf("t_iva",0) + 1
	
	//Valores de Totales
	t_importe 			= $totales.getValue(1,iImporte) * 1
	t_neto_no_gravado 	= $totales.getValue(1,iNetoNoG) * 1
	t_iva 				= $totales.getValue(1,iIva) * 1
	t_ib 				= $totales.getValue(1,iIB) * 1
	t_neto 				= $totales.getValue(1,iNeto) * 1
	
	
	//Valores Tasas
	t_iva_4 	= $tasasIva.getValue(4,iTIva) * 1;
	t_iva_3 	= $tasasIva.getValue(3,iTIva) * 1;
	t_iva_2 	= $tasasIva.getValue(2,iTIva) * 1;
	t_iva_1 	= $tasasIva.getValue(1,iTIva) * 1;
	t_neto_4 	= $tasasIva.getValue(4,iTNeto) * 1;
	t_neto_3 	= $tasasIva.getValue(3,iTNeto) * 1;
	t_neto_2 	= $tasasIva.getValue(2,iTNeto) * 1;
	t_neto_1 	= $tasasIva.getValue(1,iTNeto) * 1;
	porc_4 		= $tasasIva.getValue(4,iIvaPorc) * 1;
	porc_3 		= $tasasIva.getValue(3,iIvaPorc) * 1;
	porc_2 		= $tasasIva.getValue(2,iIvaPorc) * 1;
	porc_1 		= $tasasIva.getValue(1,iIvaPorc) * 1;
}
